<template>
	<view class="container">
		<uni-section title="学员信息" type="line"></uni-section>
		<view class="query-form">
			<view class="query-item">学号 <view class="query-item-value">{{student.studentCode}}</view></view>
			<view class="query-item">姓名 <view class="query-item-value">{{student.studentName}}</view></view>
			<view class="query-item">手机号 <view class="query-item-value">{{student.phone}}</view></view>
			<view class="query-item">生日 <view class="query-item-value">{{parseTime(student.birthday, '{y}-{m}-{d}')}}</view></view>
			<view class="query-item">缴费 <view class="query-item-value">{{student.money}}</view></view>
			<view class="query-item">报名节数 <view class="query-item-value">{{student.classNum}}</view></view>
			<view class="query-item">剩余节数 <view class="query-item-value">{{getBalanceNum}}</view></view>
			<view class="query-item">备注 <view class="query-item-value">{{student.remark}}</view></view>
		</view>
		<uni-section :title="'课时信息:共 ' + total + ' 节'" type="line"></uni-section>
		<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
			<uni-tr>
				<uni-th width="180rpx" align="center">时间</uni-th>
				<uni-th width="300rpx" align="center">教练/场馆/班次</uni-th>
				<uni-th align="center">备注</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in studentLessonList" :key="index">
				<uni-td>
					<view class="name">{{ parseTime(item.createTime, '{y}-{m}-{d}') }}</view>
					<view class="name">{{ parseTime(item.createTime, '{h}:{i}:{s}') }}</view>
				</uni-td>
				<uni-td>
					<view class="name" v-if="checkRole(['admin','manager'])">{{ item.coachName }}</view>
					<view class="name">{{ getStadiumName(item.stadiumId) }}</view>
					<view class="name">{{ getClassesName(item.classesId) }}</view>
				</uni-td>
				<uni-td>
					<view class="name remark">{{ item.remark }}</view>
				</uni-td>
			</uni-tr>
		</uni-table>
		<uni-pagination :page-size="queryParams.pageSize" :current="queryParams.pageNum" :total="total" @change="change"
			prev-text="前一页" next-text="后一页" />
		<view class="page-sum">
			<text>当前页：{{ queryParams.pageNum }}，数据总量：{{ total }} 条，每页数据：{{ queryParams.pageSize }} 条</text>
		</view>
	</view>
</template>

<script>	
	import { listLesson } from "@/api/puyu/student";
	import { parseTime } from '@/utils/common';
	import { getDicts } from "@/api/system/dict/data";
	import { checkPermi, checkRole } from "@/utils/permission";
	export default {
		data() {
			return {
				// 遮罩层
				loading: true,
				// 总条数
				total: 0,
				// 学员信息
				student: {},
				// 学员课时点名表格数据
				studentLessonList: [],
				puyuClassesOptions: [],
				puyuStadiumOptions: [],
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
				},
			}
		},
		computed: {
			getBalanceNum() {
				let balanceNum = this.student.classNum - this.total;
				return balanceNum;
			},
		},
		created() {
			getDicts("puyu_classes").then(response => {
				this.puyuClassesOptions = response.data;
			});
			getDicts("puyu_stadium").then(response => {
				this.puyuStadiumOptions = response.data;
			});
			this.getList();
		},
		onLoad(option) {
			  const item = JSON.parse(decodeURIComponent(option.item));
			  this.student = item;
		},
		onShow() {
			this.getList();
		},
		methods: {
			parseTime,
			checkPermi,
      checkRole,
			/** 查询课时点名列表 */
			getList() {
				this.loading = true;
				this.queryParams.studentId = this.student.studentId;
				this.queryParams.orderByColumn = 'lessonStudentId'; //查询字段是表格中字段名字
				this.queryParams.isAsc = 'descending'; //动态取值排序顺序
				listLesson(this.queryParams).then(response => {
					this.studentLessonList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.getData(e.current)
			},
			// 获取数据
			getData(pageCurrent, value = '') {
				this.queryParams.pageNum = pageCurrent
				this.getList()
			},
			// 根据classesId获取班次
			getClassesName(classesId) {
				if (this.puyuClassesOptions) {
					return this.puyuClassesOptions.filter(item => item.dictValue == classesId)[0].dictLabel;
				}
				return '';
			},
			// 根据stadiumId获取场馆
			getStadiumName(stadiumId) {
				if (this.puyuStadiumOptions) {
					return this.puyuStadiumOptions.filter(item => item.dictValue == stadiumId)[0].dictLabel;
				}
				return '';
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef H5 */
	/* page {
	padding-top: 85px;
} */
	/* #endif */

	.page-sum {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.query-form {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		background-color: #ffffff;
		margin-bottom: 10px;
	}

	.query-item {
		margin: 10rpx;
		padding: 5rpx;
	}
	
	.query-item-value {
		margin-top: 5rpx;
		color: darkgray;
	}
	.remark {
		color: #993399;
		font-weight: bolder;
	}
</style>